﻿Ext.namespace('EHSubmit.Decision');
Ext.namespace('EHSubmit.Decision.CourseList');
Ext.namespace('EHSubmit.Decision.ScoreList');

//================决策数据分析==================
EHSubmit.Decision.ScoreList.ColumnModel = new Ext.grid.ColumnModel([
    { header: '学生ID', width: 150, sortable: true, hidden: false, dataIndex: 'StudentID' },
    { header: '学生姓名', width: 150, sortable: true, hidden: false, dataIndex: 'StudentName' },
    { header: '系统建议平时分', width: 150, sortable: true, hidden:false, dataIndex: 'Average' }
]);
// 某课程所有作业的 数据源
EHSubmit.Decision.ScoreList.DataStore = new Ext.data.Store({
    baseParams: { Op: 'student', courseId: '' },      // 需要传递操作参数  sid学生的ID
    proxy: new Ext.data.HttpProxy({ url: EHSubmit.ajaxRoot + 'AnalysisHandler.ashx' }),  //后台具体处理

    reader: new Ext.data.JsonReader({
            totalProperty: 'count',    //总记录个数
            root: 'data',
            id: 'StudentID'
        },
        [   // 数据模型
            { name: 'StudentID' },
            { name: 'StudentName' },
            { name: 'Average' }
    ]),
    listeners: {
        /// 加载异常处理
        exception: function(proxy, type, action, options, response){
            Ext.MessageBox.alert('数据加载错误!','请与管理员联系');
            
        }
    }
});

EHSubmit.Decision.ScoreList.GridPanel = {
    xtype: 'grid',
    title: '建议平时成绩',
    id: 'Decision_StudentAverageGrid',
    frame: true,
    //autoExpandColumn: 3, 
    //autoHeight: true,       // 自动调整高度
	autoWidth:true,
    height: 400,
    loadMask: true,           // 加载数据时遮住
    ds: EHSubmit.Decision.ScoreList.DataStore,
    cm: EHSubmit.Decision.ScoreList.ColumnModel
};

//================== 课程列表 ===================
// 所授课程列模式
EHSubmit.Decision.CourseList.ColumnModel = new Ext.grid.ColumnModel([
    { header: '课程ID', width: 40, sortable: true, hidden: true, dataIndex: 'Id' },
    { header: '课程名', width: 100, sortable: true, hidden: false, dataIndex: 'Name' }
]);

EHSubmit.Decision.CourseList.DataStore = new Ext.data.Store({
    baseParams: { Op: 'List_Course' },      // 需要传递操作参数  sid学生的ID
    proxy: new Ext.data.HttpProxy({ url: EHSubmit.ajaxRoot + 'CourseHandler.ashx' }),  //后台具体处理

    reader: new Ext.data.JsonReader({
            //totalProperty: 'count',    //总记录个数
            root: 'courses',
            id: 'Id'
        },
        [   // 数据模型
            { name: 'Id' },
            { name: 'Name' }
    ]),
    listeners: {
        /// 加载异常处理
        exception: function(proxy, type, action, options, response){
            Ext.MessageBox.alert('数据加载错误!','请与管理员联系');
            
        }
    }
});
/*
 xtype: 'grid',
    title: '建议平时成绩',
    id: 'Decision_StudentAverageGrid',
    frame: true,
    //autoExpandColumn: 3, 
    //autoHeight: true,       // 自动调整高度
	autoWidth:true,
    height: 400,
    loadMask: true,           // 加载数据时遮住
    ds: EHSubmit.Decision.ScoreList.DataStore,
    cm: EHSubmit.Decision.ScoreList.ColumnModel

*/

EHSubmit.Decision.CourseList.GridPanel = {
    xtype: 'grid',
    title: '选择课程',
    id: 'Decision_ChooseCourseGrid',
    frame: true,
    //autoExpandColumn: 1, 
    //autoHeight: true,       // 自动调整高度
    height: 330,
    loadMask: true,           // 加载数据时遮住
    ds: EHSubmit.Decision.CourseList.DataStore,
    cm: EHSubmit.Decision.CourseList.ColumnModel,
    /*sm: new Ext.grid.RowSelectionModel({
        singleSelect: true             // 一次只选一个
    }),*/
    listeners: {
        render: function(thisGrid) {
            //----------请求单页数据-----------------
            thisGrid.store.load();
        },
        rowclick:function (thisGrid,rowIndex,e ){
            
            var store = thisGrid.getStore();
            var rec = store.getAt(rowIndex);
			var courseId = rec.get('Id');
            
			var store = Ext.getCmp('Decision_StudentAverageGrid').getStore();
			store.setBaseParam('courseId',courseId);
            store.load();
        },
        delay: 10 // Allow rows to be rendered.
    }

};

//============================
EHSubmit.Decision.Tab = {
    id: 'decisionForm',
	title:'平时成绩参考',
	frame: false,
	layout:'column',
    closable: true,
	bodyStyle: 'padding:5px;',
    border: false,
	defaults: { bodyStyle: 'padding:5px;', border: false },
	items: [{
        //columnWidth: 0.3,
		width: 250,
        layout: 'fit',
        items: [EHSubmit.Decision.CourseList.GridPanel]
	},
	{
		//columnWidth: 0.7,
		width:'auto',
        layout: 'fit',
        items: [EHSubmit.Decision.ScoreList.GridPanel]
	}
	]
}